/*
 * AppletDeniedMessageContainer.java
 *
 * Created on 20 Mart 2009 Cuma, 22:56
 */
package com.pegaa.uploader.ui;

import com.pegaa.uploader.config.ConfigHolder;
import com.pegaa.uploader.config.DefaultConfigHolder;
import com.pegaa.uploader.lang.Lang;
import javax.swing.JApplet;
import netscape.javascript.JSObject;

/**
 * If user does not accept security dialog we fall back to this 
 * panel to show a message to user.
 * 
 * @author  tayfun
 */
public class AppletDeniedMessageContainer extends javax.swing.JPanel {

    private JApplet applet;
    private ConfigHolder configHolder;

    /** Creates new form AppletDeniedMessageContainer */
    public AppletDeniedMessageContainer(JApplet applet) {
        initComponents();
        //
        this.applet = applet;

    }

    public void setConfigHolder(DefaultConfigHolder configHolder) {
        this.configHolder = configHolder;
        initLang();
        raiseAppletDeniedEvent();
    }

    private void initLang() {
        Lang lang = (Lang) this.configHolder.getObject("global.lang");
        this.messageLabel.setText(lang.get("fallbackgui.message"));
    }

    /**
     * Executed to indicate javascript event handler
     */
    private void raiseAppletDeniedEvent() {
        JSObject jso = (JSObject) this.configHolder.getObject("global.jso");
        try {
            jso.call("JUP_eventhandler", new String[]{"appletdenied"});
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        messageLabel = new javax.swing.JLabel();

        setLayout(new java.awt.BorderLayout());

        messageLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        messageLabel.setPreferredSize(new java.awt.Dimension(38, 50));
        add(messageLabel, java.awt.BorderLayout.PAGE_START);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel messageLabel;
    // End of variables declaration//GEN-END:variables
}
